//
//  HJReceivedTeamView.m
//  project
//
//  Created by hu on 2019/4/8.
//  Copyright © 2019 健健. All rights reserved.
//

#import "HJReceivedTeamView.h"
@interface HJReceivedTeamView ()<UITextFieldDelegate,UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIView *timeView;
@property (weak, nonatomic) IBOutlet UITextField *time_TF;
@property (weak, nonatomic) IBOutlet UIView *locationView;
@property (weak, nonatomic) IBOutlet UITextField *location_TF;
@property (weak, nonatomic) IBOutlet UITextView *leaveTextView;
@property (weak, nonatomic) IBOutlet UITextView *otherTextView;
@property (weak, nonatomic) IBOutlet UIButton *editingBtn;
@property (weak, nonatomic) IBOutlet UILabel *placeHolder;
@property (nonatomic,assign) BOOL isEdit;
@end
@implementation HJReceivedTeamView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self == [super initWithFrame:frame]) {
        self = [[NSBundle mainBundle]loadNibNamed:@"HJReceivedTeamView" owner:nil options:nil].firstObject;
        self.frame = frame;
        self.isEdit = YES;
    }
    return self;
}
-(void)awakeFromNib {
    [super awakeFromNib];
    [self.bgView rounded:UIRectCornerAllCorners radius:10];
    [self.timeView rounded:UIRectCornerAllCorners radius:8 borderColor:[UIColor colorWithHex:0xe5e5e5] borderWidth:1];
    [self.locationView rounded:UIRectCornerAllCorners radius:8 borderColor:[UIColor colorWithHex:0xe5e5e5] borderWidth:1];
    [self.leaveTextView rounded:UIRectCornerAllCorners radius:8 borderColor:[UIColor colorWithHex:0xe5e5e5] borderWidth:1];
    [self.otherTextView rounded:UIRectCornerAllCorners radius:8 borderColor:[UIColor colorWithHex:0xe5e5e5] borderWidth:1];
    self.time_TF.delegate = self;
    self.location_TF.delegate = self;
    self.leaveTextView.delegate = self;
    self.otherTextView.delegate = self;
    
}
- (IBAction)editingBtnClicked:(UIButton *)sender {
    sender.selected = !sender.selected;
    self.isEdit = sender.selected;
    [self.delegate isEditingBtnClikedWithIsEditing:self.isEdit];
}


-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (!self.isEdit) {
        switch (textField.tag) {
            case 20101:
            {
                if ([self.delegate respondsToSelector:@selector(timeTFWithText:)]) {
                    [self.delegate timeTFWithText:textField];
                }
            }
                break;
            case 20102:
            {
                if ([self.delegate respondsToSelector:@selector(locationTFWithText:)]) {
                    [self.delegate locationTFWithText:textField];
                }
            }
                break;
            default:
                break;
        }
    }
    return NO;
}
- (void)textViewDidEndEditing:(UITextView *)textView {
    NSRange rang = NSMakeRange(0, textView.text.length);
    if ([textView.text isEqualToString:@""] && rang.length == 0) {
        self.placeHolder.hidden = NO;
    }
    if (textView.tag ==20104) {
        [self.delegate otherInfoTVWithTextView:textView];
    }
}

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView {
    switch (textView.tag) {
        case 20103:
            return NO;
            break;
        case 20104:
        {
            self.placeHolder.hidden = YES;
            return YES;
        }
            break;
        default:
            break;
    }
    return NO;
}

@end
